package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Customertransaction;
import com.restaurant.service.CustomertransactionService;

public class CustomertransactionServiceImpl implements CustomertransactionService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Customertransaction addOrModify( Customertransaction objCustomertransaction ) {
       return ( Customertransaction ) hibernateTemplate.merge( objCustomertransaction );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Customertransaction deleteRecord( Customertransaction objCustomertransaction ) {
       hibernateTemplate.delete( objCustomertransaction );
       return objCustomertransaction;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Customertransaction modifyRecord( Customertransaction objCustomertransaction ) {
       return ( Customertransaction ) hibernateTemplate.merge( objCustomertransaction );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Customertransaction> loadAll() {
       return (List<Customertransaction>)hibernateTemplate.findByNamedQuery( "Customertransaction.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Customertransaction loadByPrimaryKey( Long primaryKey ) {
       return (Customertransaction) hibernateTemplate.get( Customertransaction.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Customertransaction deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Customertransaction> loadByHql(String query) {
       return ( List<Customertransaction> ) hibernateTemplate.find( query );
   }
}